home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1324 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.2 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: what is the proper way to create header files??
  5. Date: Wed, 10 Jan 1996 13:14:48 GMT
  6. Organization: Netcom
  7. Message-ID: <30f3ba2d.383635072@nntp.ix.netcom.com>
  8. References: <4cv6i3$9dg@news.ios.com>
  9. NNTP-Posting-Host: ix-dc12-01.ix.netcom.com
  10. X-NETCOM-Date: Wed Jan 10  5:13:37 AM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Keith Boruff <kboruff@village.ios.com> wrote:
  14.  
  15. |>I have spent some time scanning the included header files that came
  16. with 
  17. |>my compiler (iostream.h, math.h, cstring.h, etc...). 
  18. |>
  19. |>I have noticed that any functions that can be used from a given
  20. header 
  21. |>file has only its prototype (declaration) listed. The definitions in
  22. most 
  23. |>cases are not to be found in the header files themselves.
  24. |>
  25. |>I had learned some time ago about creating library files. I heard
  26. that a 
  27. |>library should contain an interface (header file) and and
  28. implementation 
  29. |>file. The header file contains all info pertaining to function 
  30. |>declarations and class declarations. The implementation files
  31. contain the 
  32. |>definitions of any functions. The implementation file is compiled 
  33. |>separately and then linked to any source file that includes the 
  34. |>interface. exam: #include "somefile.h"..
  35. |>
  36. |>This is sure the case with all files in my include directory. I
  37. cannot 
  38. |>figure out how including a header file with function declarations
  39. will 
  40. |>automatically include the binary file with its corresponding
  41. definitions. 
  42. |>
  43. |>The only way that I can achieve a similiar outcome is by linking my 
  44. |>driver file and header binary file together in a project. Yet I do
  45. not 
  46. |>have to do this with say: iostream.h, cstring.h, ctype.h...ad
  47. nauseum..
  48. |>
  49. |>I would like to be able to do this so that I can hide the ugly
  50. details of 
  51. |>any function definitions and only expose the programmer to what my 
  52. |>classes, functions offer.  
  53. |>
  54. |>Could someone tell me how this is achieved? I want to be able to
  55. include 
  56. |>my own header files into my driver files without the inconvenience
  57. of 
  58. |>linking two separate files in a project. 
  59. |>
  60. |>Does this method take some extensive knowledge in knowing
  61. preprocessor 
  62. |>directives. I have seen these things smeared all over the *.h text
  63. files. 
  64.  
  65. In most compilers (read: every one I know of) there is no link between
  66. the header file and the executable.  In order to use the header file,
  67. you must also link in the appropriate object or library files.
  68.  
  69. Generally, many of the implementor defined headers (including the
  70. standard headers) declare functions that are contained in standard
  71. libraries that the compiler always links in.  
  72.  
  73. For example, on UNIX systems you needn't link in any special library
  74. for most of the standard headers.  The one notable exception is
  75. <math.h>.  Most (all?) UNIX compilers do not link in some of the
  76. floating point math functions unless you explicitly do it with -lm on
  77. the command line.
  78.  
  79. PC compilers generally automatically link in all of the standard
  80. functions and some of the non-standard ones simply because they are in
  81. a library that is always linked in.  In most cases there are also
  82. non-standard functions that require linking in special libraries
  83. explicitly.
  84.  
  85.  
  86. Michael M Rubenstein
  87.